package com.zkk.web;

import com.alibaba.fastjson.JSON;
import com.zkk.pojo.User;

import com.zkk.service.UserService;
import com.zkk.service.impl.UserServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
@WebServlet("/check")
public class registerServlet extends HttpServlet {
    UserService userService = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            User user = new User();
            System.out.println(1);
            String password = req.getParameter("password");
            String telephone = req.getParameter("telephone");

            user.setTelephone(telephone);
            user.setPassword(password);
            User user1 = userService.checkRegister(user);
            req.setAttribute("user",user1);
            if(userService.existsTelephone(user.getTelephone())!=null){
                String message = "手机号已经存在，已经被注册";
                //跳回登入界面
                req.getRequestDispatcher("/pages/login/login.jsp").forward(req,resp);
            }else {
                int i = userService.addUser(user);
                req.getRequestDispatcher("/pages/userMenu.jsp").forward(req,resp);
            }
    }
    }

